<?php
    session_start();
    $connect = mysql_connect("localhost","root","");

    mysql_select_db("ics_sais_database",$connect);

    if(isset($_POST['submit'])){
        $a = $_POST[approved];
        for($i=0;$i<count($_POST[approved]);$i++)
            if(isset($a[$i])){
                mysql_query("UPDATE student SET approved='yes' WHERE student_no='".$a[$i]."'");
                //set the values to approved

            }  
    }
 //   mysql_close($connect);
?>

<html>
<head>
    	<title>ICS SAIS</title>
        
<link href="design.css" rel="stylesheet" type="text/css" />
 
<script type="text/javascript">
	 var RecaptchaOptions = { theme : 'white' };
	
	function form_type_display() {
		disable_all_forms();
		if (document.getElementById('type').value == 'student') {
			var className = 'student_form';
		} else if(document.getElementById('type').value == 'faculty'){
			var className = 'faculty_form';
		} else if(document.getElementById('type').value == 'encoder'){
			var className = 'encoder_form'
		}
		
		<!--get elements by class-->
		<!--http://stackoverflow.com/questions/3808808/how-to-get-element-by-class-in-javascript-->
		var elems = document.getElementsByTagName('*'), i;
		for (i in elems) {
			if((' ' + elems[i].className + ' ').indexOf(' ' + className + ' ')
					> -1) {
				elems[i].style.display = 'table-row';
			}
		}
	}
	
	function disable_all_forms(){
		var elems = document.getElementsByTagName('*'), i;
		var form_names = new Array();
		form_names[0] = 'student_form';
		form_names[1] = 'faculty_form';
		form_names[2] = 'encoder_form';
		for (h in form_names){
			for (i in elems) {
				if((' ' + elems[i].className + ' ').indexOf(' ' + form_names[h] + ' ')
						> -1) {
					elems[i].style.display = 'none';
				}
			}
		}
	}
</script>       

</head>
    
    <body>
   	<div id="cont">
        	<div id="header">
            	<div id="header_main">
                	<div id="mhleft">
                    </div>
                    
                    <div id="mhcenter" ice:editable="*">
                    	<img src="ics_logo_blue.png" id="logo"/>
                      <div id="label_sais">
                        	<div id="border_label">	</div>
                        <div id="label"><p>Students'Academic
Information System</p></div>
                      </div>
                  </div>
                    
                    <div id="mhright">
                    </div>
                </div>
                <div id="bottomhead">
                	<div id="bhleft">
                    </div>
                    <div id="menu_bar">
                    	<!--login-->
                        <?php if(!$_SESSION['loggin']){?>
                        <form method="post">
                          <table>
                                <tr>	<!--labels-->
                                	<td><label for="username">Username<label/></td>
                                    <td><label for="password">Password<label/></td>
                                    <td></td>
                                </tr>
                                <tr>	<!--forms-->
                                	<td><input type="text" name="username" id="username"/></td>
                                    <td><input type="password" name="password" id="password"/></td>
                                    <td><input type="submit" value="Login" name="login" class="sub_button" /></td>
                                </tr>
                            </table>
                        </form>

                        <?php }else echo "Logged in as ".$_SESSION['uname'];

                        ?>
                        <a href="logout.php">Logout</a>
                        </div>
                </div>
            </div>
      
      <div id="body">
      	<form name="checkboxes" method="post">
            <div id="innerbody">
            <table name="accountlist">        
            <?php
                $q = mysql_query("SELECT * from student");
                while($studentarray = mysql_fetch_array($q)){
                 echo "<tr>";

                    for($i=0;$i<sizeof($studentarray);$i++) {

                        if($i==0) echo "<td> <input type='checkbox' name='approved[]' value=".$studentarray[0]." /> </td>";
                        echo "<td>".$studentarray[$i]."</td>";
                    }
                echo "</tr >";
                }
            ?>
            <input type="submit" name="submit" value="Approve accounts" />
            </table>
            </div>
        </form>
        <div id="body_border">
        
        </div>
        
        <div id="announcement">
        </div>
      </div>
   	</div>
    </body>
</html>